package com.geostar.constructionland.index.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.geostar.constructionland.index.entity.model.IndexCancelModel;
import com.geostar.constructionland.index.entity.server.ServerResponse;
import com.geostar.constructionland.index.service.IndexCancelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/***
 * 指标作废
 * @author wuyongzhi
 */
@RestController
@RequestMapping("/indexCancel")
@Api(tags = "指标作废相关接口")
public class IndexCancelController {

    @Resource
    IndexCancelService indexCancelService;

    @ApiOperation(value = "根据业务id作废指标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "businessId", value = "业务id", required = true),
            @ApiImplicitParam(name = "cancelReason", value = "作废原因", required = true),
            @ApiImplicitParam(name = "operatorId", value = "操作人id", required = true)
    })
    @PostMapping(value = "/cancelIndex")
    @ResponseBody
    public ServerResponse cancelIndex(@Valid IndexCancelModel indexCancelModel) {
        ServerResponse serverResponse = ServerResponse.createBySuccess();
        String businessId = indexCancelModel.getBusinessId();
        String cancelReason = indexCancelModel.getCancelReason();
        String operatorId = indexCancelModel.getOperatorId();
        if(StringUtils.isNotBlank(businessId) && StringUtils.isNotBlank(cancelReason) && StringUtils.isNotBlank(operatorId)) {
            indexCancelService.cancelIndex(indexCancelModel);
        } else {
            serverResponse = ServerResponse.createByErrorMessage("传入参数有误：业务ID，作废原因和操作人id不能为空！");
        }
        return serverResponse;
    }
}
